package com.dayuanit.dy17.atm.atmbackoffice.controller;

import com.dayuanit.dy17.atm.atmbackoffice.dto.ResponseDTO;
import com.dayuanit.dy17.atm.atmbackoffice.service.IPowerService;
import com.dayuanit.dy17.atm.atmbackoffice.vo.PowerRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
public class PowerController extends BaseController {

    @Autowired
    private IPowerService powerService;

    @RequestMapping("/power/addPower")
    public ResponseDTO addPower(PowerRequestVO powerRequestVO) {
        powerService.addPower(powerRequestVO);
        return ResponseDTO.success();
    }

    @RequestMapping("/power/loadFirstMenu")
    public ResponseDTO loadFirstMenu() {
        return ResponseDTO.success(powerService.listPower(1));
    }

    @RequestMapping("/power/loadAllMenu")
    public ResponseDTO loadAllMenu() {
        return ResponseDTO.success(powerService.listMenu());
    }

    @RequestMapping("/power/addRolePower")
    public ResponseDTO addRolePower(long roleId, @RequestParam("powerIds[]") Set<Long> powerIds) {
        System.out.println(roleId);
        powerIds.forEach(System.out::println);

        powerService.addRolePower(roleId, powerIds);
        return ResponseDTO.success();
    }
}
